home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 6804 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.3 KB

  1. Path: rcp6.elan.af.mil!rscernix!danpop
  2. From: danpop@mail.cern.ch (Dan Pop)
  3. Newsgroups: comp.arch.arithmetic,comp.lang.c,comp.lang.c++
  4. Subject: Re: Access carry flag from C
  5. Date: 19 Feb 96 21:38:03 GMT
  6. Organization: CERN European Lab for Particle Physics
  7. Message-ID: <danpop.824765883@rscernix>
  8. References: <Dn1C9z.DGv.0.net@indra.com>
  9. NNTP-Posting-Host: ues5.cern.ch
  10. X-Newsreader: NN version 6.5.0 #7 (NOV)
  11.  
  12. In <Dn1C9z.DGv.0.net@indra.com> sullivan@indra.com (Steve Sullivan) writes:
  13.  
  14. >Is it possible to determine if a fixed point overflow has
  15. >occurred from within C?  For example:
  16. >   i = j + k;
  17. >   if (overflowed) ....;
  18.  
  19. In C, signed integer arithmetic overflow causes undefined behaviour.
  20. If a method for detecting the overflow exists, it is inherently 
  21. platform specific.
  22.  
  23. Unsigned arithmetic is performed modulo the number that is
  24. one greater than the largest value that can be represented by the
  25. resulting unsigned integer type, so you can detect the "overflow",
  26. by using various arithmetic tricks.  In the particular case of addition,
  27. if the result is not greater than both operands, the result "wrapped 
  28. around".
  29.  
  30. There is no carry flag in C and the language doesn't provide direct
  31. access to the underlying hardware features.
  32.  
  33. Dan
  34. --
  35. Dan Pop
  36. CERN, CN Division
  37. Email: danpop@mail.cern.ch 
  38. Mail:  CERN - PPE, Bat. 31 R-004, CH-1211 Geneve 23, Switzerland
  39.